package com.woniuxy.homepage.core.controller;


import com.woniuxy.common.CommonResult;
import com.woniuxy.homepage.core.mapper.CarMycarMapper;
import com.woniuxy.homepage.core.model.CarMycar;
import com.woniuxy.homepage.core.service.CarMycarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-06-30
 */
@RestController
@RequestMapping("/carMycar")
@Api(tags = "我的车辆接口")
public class CarMycarController {
    @Resource
    private CarMycarService service;

    @Resource
    private CarMycarMapper carMycarMapper;


    /**
     * Description : 根据用户id查询车辆  <br/>
     * ChangeLog : 1. 创建 (2021/7/1 11:43 [Hello Mr. Guo]);
     * @param userId
     * @return com.woniuxy.common.CommonResult<com.woniuxy.homepage.core.model.CarMycar>
    */
    @ApiOperation("根据用户ID查询车辆")
    @GetMapping("/selectMyCar/{userId}")
    public CommonResult<List<CarMycar> > selecMyCar(@PathVariable("userId") Integer userId){
        List<CarMycar> list = this.service.selectMyCar(userId);
        if (list == null){
            return CommonResult.fail("查询我的车辆失败");
        }
        return CommonResult.success(list);
    }


    /**
     * Description : 添加我的车辆  <br/>
     * ChangeLog : 1. 创建 (2021/7/1 15:02 [Hello Mr. Guo]);
     * @param carMycar
     * @return com.woniuxy.common.CommonResult
    */
    @ApiOperation("添加我的车辆")
    @PostMapping("/insetMyCar")
    public CommonResult insertMyCar(@RequestBody CarMycar carMycar){
        int insert = this.carMycarMapper.insert(carMycar);
        if (insert > 0){
            return CommonResult.success();
        }
        return CommonResult.fail("添加车辆失败");
    }



}

